package com.jxud.controller;

import com.jxud.pojo.Dept;
import com.jxud.pojo.Emp;
import com.jxud.pojo.Result;
import com.jxud.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {

    @Autowired
    private  DeptService deptService;
//    private static Logger log = LoggerFactory.getLogger(DeptController.class);  // 引入日志对象   通过@slf4j实现同样的效果

//    @RequestMapping(value = "/depts",method = RequestMethod.GET)

    /**
     * 查询部门数据
     * @return
     */
    @GetMapping
    public Result list(){
        List<Dept>  deptList = deptService.list();
        log.info("查看全部部门数据");
        return Result.success(deptList);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("根据id删除部门:{}",id);
        deptService.delete(id);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Dept dept){
        log.info("新增部门:{}",dept);
        deptService.add(dept);
        return Result.success();
    }
}
